<import file="block/common.html" name="url"/>
<div class="layui-fluid">
<div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body ">
                <blockquote class="layui-elem-quote">当前角色：<b style="color: red;"><{$info['groupname']}></b> (超级管理员不受菜单权限限制)</blockquote>
            </div>
        </div>
    </div>
</div>	

<div class="layui-form">
<form class="layui-form" action="">
<fieldset class="layui-elem-field">
  <legend>后台系统菜单权限管理</legend>
  <div class="layui-field-box">
   <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-block">
	<div id="menuCateTree" class="dtree" data-id="0"></div>
    </div>
  </div>
</div>
</fieldset>

<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="saveBtn"><?php echo lang('save');?></button>
    </div>
</div>
</form>
</div>
</div>
<script>
    layui.use(['dtree','form'], function () {
        var form = layui.form,
            layer = layui.layer,
            dtree = layui.dtree,
            $ = layui.$;
			
		// 初始化树
    dtree.render({
		elem: "#menuCateTree",
		url: "<{caUrl('adminmenu','index')}>&tree_json", // 使用url加载（可与data加载同时存在）
		dataStyle: "layuiStyle",  //使用layui风格的数据格式
		//dataFormat: "list",  //配置data的风格为list
		response:{message:"msg",statusCode:0},  //修改response中返回数据的定义
		checkbar: true,  
		checkbarType: "all", // 默认就是all，其他的值为： no-all  p-casc   self  only
		checkbarData: "choose",// 记录选中（默认）， "change"：记录变更， "all"：记录全部， "halfChoose"："记录选中和半选（V2.5.0新增）"
		done: function(res, $ul, first){
			if(first) {
			  dtree.chooseDataInit("menuCateTree","<{$menuid}>"); // 初始化选中
			}
		  }
    });

	form.render();

    //监听提交
    form.on('submit(saveBtn)', function (data) {
		var params = dtree.getCheckbarJsonArrParam("menuCateTree");
		$.post('<{caUrl("admingroup","menurole")}>',{id:'<{$info["id"]}>',menurole:params.nodeId},function(res){
            if(res.status == 1){
                layer.msg(res.info, {icon: 1, time: 1000},function(){
					loadMain('<{caUrl("admingroup","index")}>');
				});
            }else{
                layer.msg(res.info, {icon: 2, anim: 6, time: 5000});
            }
        });
        return false;
    });
    });
</script>